<?php

class DbRelationEntity extends DbEntity
{
    public function onExtracting( $id, array $val, IDbMapper $chain )
    {
        if( ! isset( $val[self::KEY_RELATION] ) ) return false;
        $chain->relations[ $id ] = $val;
		$chain->properties[ $id ] = array();
		$chain->fieldMaps[ $val[self::KEY_RELATION] ] = $id;
		if( isset( $val[self::KEY_IS_FIELD] ) )
		{
			$chain->fields[] = $val['relation'];
		}
		
		if( ! isset( $chain->relations[ $id ][self::KEY_RPRIMARY] ) )
		{
			$chain->relations[ $id ][self::KEY_RPRIMARY] = $val[self::KEY_RELATION];
		}
    }
}
